<?php

namespace common\app;

use yii;

class User
{
    public $key = '';

    private function init()
    {
        if (empty($this->key)) {
            echo "没有设置登录的session key";
            exit;
        }
    }

    function isGuest()
    {
        $data = $this->getIdentity();
        if ($data && !empty($data)&&$data!=null)
            return false;
        return true;
    }

    function setSessionKey($key)
    {
        $this->key = $key;
    }

    function getIdentity()
    {
        $this->init();
        return yii::$app->session->get($this->key);
    }

    function setIdentity($identity)
    {
        $this->init();
        yii::$app->session->set($this->key, $identity);
    }

    function logout()
    {
        yii::$app->session->destroy();
    }
}

